package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import dao.CategoriasDao;
import dao.CategoriasDaoImpl;

import model.Categoria;

public class CategoriaTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		List<Categoria> listaCat = new ArrayList<Categoria>();
		CategoriasDao cDao = new CategoriasDaoImpl();
		JspWriter out = getJspContext().getOut();
		try {
			listaCat = cDao.consultaListaCategorias();
			for (Categoria c : listaCat){
				StringBuffer linha = new StringBuffer();
				linha.append("<tr id=\"");
				linha.append(c.getId());
				linha.append("\">");
				linha.append("<td class=\"checkbox\"><input type=\"checkbox\" name=\"");
				linha.append(c.getId());
				linha.append("\" /></td>");
				linha.append("<td>");
				linha.append(c.getId());
				linha.append("</td>");
				linha.append("<td>");
				linha.append(c.getTipo());
				linha.append("</td>");
				linha.append("<td>");
				linha.append("<a href=\"${pageContext.request.contextPath}/excluircategoria\" class=\"button form_submit red\"><small class=\"icon cross\"></small><span>Excluir</span></a>");
				linha.append("<input type=\"submit\" value=\"Submit\" class=\"novisible\" />");
				linha.append("</td>");
				linha.append("</tr>");
				out.println(linha.toString());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
